package order

import (
	"context"

	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/ent/pancakebotorder"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/internal/svc"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/internal/utils/dberrorhandler"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/types/pancakebot"
	"github.com/suyuan32/simple-admin-common/i18n"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeletePancakebotOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeletePancakebotOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePancakebotOrderLogic {
	return &DeletePancakebotOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeletePancakebotOrderLogic) DeletePancakebotOrder(in *pancakebot.IDsReq) (*pancakebot.BaseResp, error) {
	// 批量删除订单
	_, err := l.svcCtx.DB.PancakebotOrder.Delete().
		Where(pancakebotorder.IDIn(in.Ids...)).
		Exec(l.ctx)

	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, in)
	}

	return &pancakebot.BaseResp{
		Msg: i18n.DeleteSuccess,
	}, nil
}
